package org.dromara.system.controller.system;

import cn.hutool.core.lang.Assert;
import com.lxk.ip.core.Area;
import com.lxk.ip.core.utils.AreaUtils;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.domain.vo.AreaNodeRespVO;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 行政区划
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/area")
public class SysAreaController {

    @GetMapping("/tree")
    @Operation(summary = "获得地区树")
    public R<List<AreaNodeRespVO>> getAreaTree() {
        Area area = AreaUtils.getArea(Area.ID_CHINA);
        Assert.notNull(area, "获取不到中国");
        return R.ok(BeanCopyUtils.copyList(area.getChildren(), AreaNodeRespVO.class));
    }
}
